<?php
namespace Logic;

use Hoa\Registry\Registry;
use Library\Log;
use Library\Redis;
use Model\Card;


/**
 * @name CardLogic
 * @author Los
 */
class CardLogic extends BaseLogic {
	/**
	 * test
	 */
	static public function test() {
		return __METHOD__;
	}


	/**
	 * 缓存新卡的code列表
	 * @return bool|int
	 */
	static public function cacheNewCardCodeList() {
		$redis_key = 'card:code:new';
		if (Redis::exists($redis_key) && Redis::llen($redis_key) > 0) {
			return true;
		}
		$code_list = Card::getNewCardCodeList(1000);
		Log::debug(__METHOD__ . ': $code_list = ' . var_export($code_list, true));
		if ($code_list) {
			Redis::lpush($redis_key, $code_list);
		}
		//返回新缓存的新卡数量
		return count($code_list);
	}


	/**
	 * 获取新卡的数量
	 * @return int
	 */
	static public function getNewCardCnt() {
		$redis_key = 'card:code:new';
		self::cacheNewCardCodeList();
		return Redis::llen($redis_key);
	}





}